
#-*-coding:utf-8-*-#

import os
import numpy as np
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt

currentPath = os.getcwd()
os.chdir('PATH')

EMM = pd.read_csv('Data_Fig2b_1.csv', index_col=0) # Wildfire data with negative sentiment and network information
W = nx.read_gexf('Data_Fig2a_2.gexf') # Wildfire graph data

#From the start of awareness increase
Emp_data = EMM[70:]
Emp_data['Count'] = Emp_data['Count'] - Emp_data['Count'][70]
Emp_data = Emp_data.reset_index(drop=True)

degrees = dict(W.degree())

pos_degrees_vals = list(filter(lambda val: val > 0, degrees.values()))
sum(pos_degrees_vals)/len(pos_degrees_vals)
uq_pos_degrees_vals = sorted(set(pos_degrees_vals))
hist = [pos_degrees_vals.count(x) for x in uq_pos_degrees_vals]

x = np.asarray(uq_pos_degrees_vals, dtype = float)
y = np.asarray(hist, dtype = float)

logx = np.log10(x)
logy = np.log10(y)

logk_interp = np.linspace(np.min(logx),np.max(logx[:50]),1000)
logPk_interp = np.interp(logk_interp, logx[:50], logy[:50])
plt.plot(logk_interp, logPk_interp,".")
plt.show()
m, c = np.polyfit(logk_interp, logPk_interp, 1)

plt.figure(figsize=(5,5),dpi=400)
plt.xlim(min(logx), max(logx))
plt.ylim(-0.2, 4)
plt.xlabel('log10 (Degree)')
plt.ylabel('log10 (Number of nodes)')
scatter_plot = plt.plot(logx, logy, 'o', color='k')
plt.plot(logk_interp, m*logk_interp + c, "-",color='orange')
plt.text(1,2,'logy = -3.0 logx + 3.5',fontsize=14)
plt.axhline(y=0,color='black',linestyle='--')
plt.xlim([0,3.5])
plt.tight_layout()
plt.show()
